<template>
  <div class="app-container">
    <header class="header">
      <nav class="nav">
        <div class="logo">
          <span class="logo-text">Elegant</span>
          <span class="logo-dot">.</span>
          <span class="logo-blog">Blog</span>
        </div>
        <div class="nav-links">
          <a href="#" class="nav-link" :class="{ active: isActive('/') }" @click.prevent="navigateTo('/')">首页</a>
          <a href="#" class="nav-link" :class="{ active: isActive('/archive') }" @click.prevent="navigateTo('/archive')">归档</a>
          <a href="#" class="nav-link" :class="{ active: isActive('/about') }" @click.prevent="navigateTo('/about')">关于</a>
          <div class="search-box">
            <input 
              type="text" 
              placeholder="搜索文章..." 
              @focus="showSearch = true"
              @blur="handleSearchBlur"
              v-model="searchQuery"
            />
            <div class="search-results" v-if="showSearch && searchResults.length">
              <router-link 
                v-for="result in searchResults" 
                :key="result.id"
                :to="{ name: 'post', params: { id: result.id }}"
                class="search-result-item"
                @click="showSearch = false"
              >
                {{ result.title }}
              </router-link>
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="main-content">
      <transition name="fade" mode="out-in">
        <router-view></router-view>
      </transition>
    </main>

    <footer class="footer">
      <div class="footer-content">
        <div class="footer-section">
          <h3>关于博客</h3>
          <p>分享技术与生活的个人空间</p>
        </div>
        <div class="footer-section">
          <h3>联系方式</h3>
          <div class="social-links">
            <a href="#" title="GitHub"><i class="fab fa-github"></i></a>
            <a href="#" title="微信"><i class="fab fa-weixin"></i></a>
            <a href="#" title="邮箱"><i class="fas fa-envelope"></i></a>
          </div>
        </div>
      </div>
      <div class="footer-bottom">
        <p>&copy; 2024 Elegant Blog. All rights reserved.</p>
      </div>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()
const store = useStore()
const showSearch = ref(false)
const searchQuery = ref('')

const searchResults = computed(() => {
  if (!searchQuery.value) return []
  const query = searchQuery.value.toLowerCase()
  return store.state.posts.list.filter(post => 
    post.title.toLowerCase().includes(query) ||
    post.content.toLowerCase().includes(query)
  ).slice(0, 5)
})

const handleSearchBlur = () => {
  setTimeout(() => {
    showSearch.value = false
  }, 200)
}

const navigateTo = (path) => {
  if (router) {
    router.push(path)
  }
}

const isActive = (path) => {
  return route?.path === path || false
}
</script>

<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #3498db;
  --secondary-color: #2ecc71;
  --text-color: #2c3e50;
  --light-gray: #f5f6fa;
  --border-color: #dcdde1;
}

body {
  font-family: 'Poppins', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--light-gray);
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.nav {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.8rem;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
}

.logo-text {
  color: var(--text-color);
}

.logo-dot {
  color: var(--primary-color);
  margin: 0 2px;
}

.logo-blog {
  color: var(--secondary-color);
}

.nav-links {
  display: flex;
  gap: 2rem;
  align-items: center;
}

.nav-links a {
  color: var(--text-color);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: all 0.3s ease;
  font-weight: 500;
}

.nav-links a:hover {
  background-color: rgba(52, 152, 219, 0.1);
  color: var(--primary-color);
}

.nav-links a.router-link-active {
  color: var(--primary-color);
  background-color: rgba(52, 152, 219, 0.1);
}

.search-box {
  position: relative;
}

.search-box input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  outline: none;
  width: 200px;
  transition: all 0.3s ease;
}

.search-box input:focus {
  width: 300px;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.main-content {
  flex: 1;
  margin-top: 80px;
  padding: 20px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.footer {
  background-color: #fff;
  padding: 40px 20px 20px;
  margin-top: auto;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 40px;
  margin-bottom: 30px;
}

.footer-section h3 {
  color: var(--text-color);
  margin-bottom: 15px;
}

.social-links {
  display: flex;
  gap: 20px;
}

.social-links a {
  color: var(--text-color);
  font-size: 1.5rem;
  transition: color 0.3s ease;
}

.social-links a:hover {
  color: var(--primary-color);
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.nav-link {
  position: relative;
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--text-color);
  font-weight: 500;
  transition: all 0.3s ease;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background-color: var(--primary-color);
  transition: width 0.3s ease;
}

.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: 8px;
  overflow: hidden;
}

.search-result-item {
  display: block;
  padding: 10px 15px;
  color: var(--text-color);
  text-decoration: none;
  transition: background-color 0.3s ease;
}

.search-result-item:hover {
  background-color: var(--light-gray);
  color: var(--primary-color);
}
</style>
